package com.dc.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_calibration_paint_house")
public class CalibrationPaintHouseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ship_id", columnDefinition = "bigint unsigned NOT NULL")
    private ShipEntity ship;

    @Transient
    private Long shipId;

    @Transient
    private String shipName;

    @Column(name = "area")
    public Double area;        // 油漆面积(m²)

    @Column(name = "project", length = 50)
    private String project;     // 工程项目

    @Column(name = "powers")
    public Double powers;      // 耗电能(kwh) 动态计算

    @Column(name = "power_by_unit")
    public Double powerByUnit; // 单位耗电（KWh/m2） 动态计算

    @Column(name = "start_air")
    public Double startAir;    // 压缩空气起始读数

    @Column(name = "end_air")
    public Double endAir;      // 压缩空气结束读数

    @Column(name = "air")
    public Double air;         // 耗压缩空气量(m³)  动态计算

    @Column(name = "air_by_unit")
    public Double airByUnit;   // 单位用压缩空气量(m³/m²) 动态计算

    @Column(name = "gas_by_hour")
    public Double gasByHour;   // VOCs设备耗气量(m³/h)

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "start_gas")
    public Date startGas;    // 天然气开始时间

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "end_gas")
    public Date endGas;      // 天然气结束时间

    @Column(name = "gas")
    public Double gas;         // 耗天然气量(m³) 动态计算

    @Column(name = "gas_by_unit")
    public Double gasByUnit;   // 单位耗天然气量(m³)  动态计算

    @JsonIgnoreProperties(value = { "calibrationPaintHouseEntity" })
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinColumn(name = "calibration_paint_house_id", referencedColumnName = "id")
    private List<CalibrationPaintHouseChildEntity> inner = new ArrayList<>();

    @Override
    public String toString() {
        return "CalibrationPaintHouseEntity{" +
                "id=" + id +
                ", ship=" + ship +
                ", shipId=" + shipId +
                ", shipName='" + shipName + '\'' +
                ", area=" + area +
                ", project='" + project + '\'' +
                ", powers=" + powers +
                ", powerByUnit=" + powerByUnit +
                ", startAir=" + startAir +
                ", endAir=" + endAir +
                ", air=" + air +
                ", airByUnit=" + airByUnit +
                ", gasByHour=" + gasByHour +
                ", startGas=" + startGas +
                ", endGas=" + endGas +
                ", gas=" + gas +
                ", gasByUnit=" + gasByUnit +
                ", inner=" + inner.size() +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CalibrationPaintHouseEntity that = (CalibrationPaintHouseEntity) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
